package EventManager;

import java.io.IOException;

import GameFiles.GameManager;
import GameStates.GameOver;
import GameStates.OptionsMenu;
import GameStates.RunGame;
import Gui.AboutPanel;
import Gui.InstructionsPanel;
import PlayerManager.PlayerManager;
import PlayerStates.FinalLoad;
import PlayerStates.HandleDay;
import PlayerStates.InitialLoad;

public class StateMachineListener extends Listener
{
	public void init()
	{
		EventType event = new EventType("EVENT_START_GAME");
		addEventMonitor(event);
		event.setName("EVENT_OPTIONS_MENU");
		addEventMonitor(event);
		event.setName("EVENT_INSTRUCTIONS_MENU");
		addEventMonitor(event);
		event.setName("EVENT_HANDLE_DAY");
		addEventMonitor(event);
		event.setName("EVENT_FINAL_LOAD");
		addEventMonitor(event);
		event.setName("EVENT_ABOUT_LOAD");
		addEventMonitor(event);
		event.setName("EVENT_GAME_OVER");
		addEventMonitor(event);
	}

	public boolean HandleEvent(EventType event)
	{
		if (event.getName().equals("EVENT_START_GAME")) {
			try
			{
				GameManager.getInstance().InitializeGame();
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			GameManager.getInstance().ChangeGameState(RunGame.getInstance());
			return true;
		} else if (event.getName().equals("EVENT_OPTIONS_MENU")) {
			GameManager.getInstance().ChangeGameState(OptionsMenu.getInstance());
			return true;
		} else if (event.getName().equals("EVENT_INSTRUCTIONS_MENU")) {
			//GameManager.getInstance().ChangeGameState(InstructionsMenu.getInstance());
			InstructionsPanel.getInstance().setVisible(true);
			return true;
		} else if (event.getName().equals("EVENT_HANDLE_DAY")) {
			PlayerManager.getInstance().ChangeCurrentPlayerState(HandleDay.getInstance());
			return true;
		} else if (event.getName().equals("EVENT_INITIAL_LOAD")) {
			PlayerManager.getInstance().ChangeCurrentPlayerState(InitialLoad.getInstance());
			return true;
		}else if (event.getName().equals("EVENT_FINAL_LOAD")) {
			PlayerManager.getInstance().ChangeCurrentPlayerState(FinalLoad.getInstance());
			return true;
		}else if (event.getName().equals("EVENT_ABOUT_LOAD")){
			AboutPanel.getInstance().setVisible(true);
			return true;
		}else if (event.getName().equals("EVENT_GAME_OVER")){
			GameManager.getInstance().ChangeGameState(GameOver.GetInstance());
			return true;
		}
		return false;
	}
}
